﻿package UIComponents
{
	import MyComponent.MyButton;
	
	import com.greensock.easing.Back;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * 弹出窗口基本的背景类  
	 * @author Administrator
	 */	
	public class BeathartWindon extends Sprite
	{
		private var centerBtn:MyButton;
		public function BeathartWindon()
		{
			init();
		}
		
		private function init():void
		{
			this.centerBtn=this.getChildByName("windowCenterBtn") as MyButton;
			this.centerBtn.mouseChildren=false;
			(this.getChildByName("CenterBtnTxt") as TextField).selectable=false;
			(this.getChildByName("CenterBtnTxt") as TextField).mouseEnabled=false;
			
			(this.getChildByName("windonContext") as TextField).selectable=false;
			(this.getChildByName("windonContext") as TextField).mouseEnabled=false;
			
			(this.getChildByName("rewardTxt") as TextField).selectable=false;
			(this.getChildByName("rewardTxt") as TextField).mouseEnabled=false;
			
			for(var i:int=0;i<3;i++)
			{
				var dc:DisplayObjectContainer=this.getChildByName("rd"+i) as DisplayObjectContainer;
				dc.getChildByName("qqtq").visible=false;
				dc.getChildByName("fsbq").visible=false;
			}
			initAddListener();
		}
		
		private function initAddListener():void
		{
			centerBtn.addEventListener(ComponentEvent.BUTTON_DOWN,clickCenterBtn);
		}
		
		private function clickCenterBtn(e:ComponentEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.SHARENEWTHINGS,true));
		}
		
		/**
		 * 设置窗口栏头部是否显示 
		 * @param arg1 星星
		 * @param arg2 
		 */		
		public function setWindonHeadVisabe(arg1:Boolean,arg2:Boolean):void
		{
			(this.getChildByName("bgLayer") as DisplayObjectContainer).getChildByName("startMc").visible=arg1;
			(this.getChildByName("bgLayer") as DisplayObjectContainer).getChildByName("ttMc").visible=arg2;
			this.getChildByName("shandongxx").visible=arg1;
		}
		
		/**
		 * 设置窗口 
		 * @param obj
		 */		
		public function setWinInfo(obj:Object):void
		{
			 this.reset();
			(this.getChildByName("windonIconTitle") as IconContainer).addPic(obj.windonIconTitle);
			(this.getChildByName("windonContext") as TextField).text=obj.windonContext;
			(this.getChildByName("rewardTxt") as TextField).text=obj.rewardTxt;
			(this.getChildByName("CenterBtnTxt") as TextField).text=obj.CenterBtnTxt;
			
			var tmparr:Array=obj.items;
			for(var i:int=0;i<tmparr.length;i++)
			{
				if(i>2)return;
				var item:Object=tmparr[i];
				var dc:DisplayObjectContainer=this.getChildByName("rd"+i) as DisplayObjectContainer;
				dc.visible=true;
				if(FlatInfo.isOpenHz && i==2)
				{
					dc.getChildByName("qqtq").visible=true;
//					dc.visible=true;
				}else{
					dc.getChildByName("qqtq").visible=false;
//					dc.visible=false;
				}
				if(i==1)
				{
					dc.getChildByName("fsbq").visible=true;
				}else{
					dc.getChildByName("fsbq").visible=false;
				}
				
				((dc.getChildByName("piliang")as DisplayObjectContainer).getChildByName("txt_num") as TextField).text=item.num;
				if(item.lock)
				{
					dc.getChildByName("lock").visible=true;
				}else{
					dc.getChildByName("lock").visible=false;
				}
				var dis:DisplayObject=item.pic;
				dis.width=75;
				dis.height=75;
				(dc.getChildByName("rewardPic") as IconContainer).addPic(dis,item.discript);
			}
		}
		

		private function reset():void
		{
			(this.getChildByName("windonIconTitle") as IconContainer).addPic(null);
			(this.getChildByName("windonContext") as TextField).text="";
			(this.getChildByName("rewardTxt") as TextField).text="";
			(this.getChildByName("CenterBtnTxt") as TextField).text="";
			this.rd();
			
		}
		private function rd(v:Boolean=false):void
		{
			for(var i:int=0;i<3;i++)
			{
				var dc:DisplayObjectContainer=this.getChildByName("rd"+i) as DisplayObjectContainer;
				dc.visible=v;
			}
		}
		
		/**
		 * 移除注册事件 
		 */		
		public function release():void
		{
			centerBtn.removeEventListener(ComponentEvent.BUTTON_DOWN,clickCenterBtn);
		}
		
	}
}